#!/bin/bash

ANSIBLE_ROLE_PATH="/etc/ansible/roles"
ROLES_NAME=${1}
ROLES_DIRS=(
defaults
files
handlers
meta
tasks
templates
vars
)

EXIT_ROLES=(`ls -al ${ANSIBLE_ROLE_PATH} | tail -n +2 | grep -Ev "\.+" | awk '{print $NF}'`)

function CreateRolesDirs(){
	for NAME in ${ROLES_DIRS[@]};do
		/bin/mkdir -p ${ANSIBLE_ROLE_PATH}/${ROLES_NAME}/${NAME}
		[[ $? == 0 ]] && echo "Roles ${ROLES_NAME}/${NAME} dirs had created."
		/bin/touch ${ANSIBLE_ROLE_PATH}/${ROLES_NAME}/${NAME}/main.yml
	done
	tree ${ANSIBLE_ROLE_PATH}/${ROLES_NAME}
}

[[ $# != 1 ]] && echo "Please enter the roles name" && exit 0

echo "${EXIT_ROLES[@]}" | grep -wq "${ROLES_NAME}" && echo "The ${ROLES_NAME} roles had exited." && exit 0

CreateRolesDirs ${ROLES_NAME}

